package com.example.pureman.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.example.pureman.myapplication.aidl.AIDLActivity;
import com.example.pureman.myapplication.bluetooth.BluetoothActivity;
import com.example.pureman.myapplication.service.Earthquake;
import com.example.pureman.myapplication.sqlite.DatabaseSkeletonActivity;
import com.example.pureman.myapplication.sqlite.ToDoListActivity;
import com.example.pureman.myapplication.utils.CommonLog;

public class MainActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listview);

        LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);

        ListView listView = (ListView) findViewById(android.R.id.list);
        String[] names = {"ndk", "aidl", "bluetooth", "sqlite", "service"};
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, names);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String name = (String) parent.getItemAtPosition(position);
                CommonLog.d("onItemClick-->" + name);
                Intent intent = null;
                switch (name) {
                    case "ndk":
                        intent = new Intent(MainActivity.this, NDKActivity.class);
                        break;
                    case "aidl":
                        intent = new Intent(MainActivity.this, AIDLActivity.class);
                        break;
                    case "bluetooth":
                        intent = new Intent(MainActivity.this, BluetoothActivity.class);
                        break;
                    case "sqlite":
//                        intent = new Intent(MainActivity.this, DatabaseSkeletonActivity.class);
                        intent = new Intent(MainActivity.this, ToDoListActivity.class);
                        break;
                    case "service":
                        intent = new Intent(MainActivity.this, Earthquake.class);
                        break;
                }
                if (intent != null) {
                    startActivity(intent);
                }
            }
        });
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
